#ifndef REGISTERBLOCK_H_
#define REGISTERBLOCK_H_

#include "../util/definitions.h"

#include "../shared/DBRegister.h"

class RegisterBlock {

	private:
		DBRegister	regs[REGISTER_BLOCK_MAX_SIZE];
		bool		valid[REGISTER_BLOCK_MAX_SIZE];	/* true si el registro es valido */
		size_t		_size;
		size_t		_count;

	public:

		RegisterBlock();

		void init();

		/* se obtiene un registro mediante su nombre */
		const DBRegister* get(std::string &name);

		int add(const DBRegister* reg);

		int remove(const DBRegister* reg);

		int update(const DBRegister* reg);

		size_t size() {
			return _count;
		}

		void print(int id) {
			if ( id > 0 && id <_size && valid[id])
				regs[id].print();
		}

		/* loads registers from file. Returns -1 if reach eof*/
		int load(int fd);

		/* saves valid registers to file */
		void save(int fd);
	};
#endif /* REGISTERBLOCK_H_ */
